<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<%=path %>/layui/css/layui.css">
  <link rel="stylesheet" href="<%=path %>/layui/css/lxq.css">
    <script type="text/javascript" src="<%=path %>/layui/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=path %>/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=path %>/layui/util.js" charset="utf-8"></script>
</head>
<body>
<div class="lxq-body">
	<div class="layui-row lxq-address">
		位置：信息管理>学籍信息
		<hr>
	</div>





  <div class="layui-row layui-col-space10">
   <div class="layui-col-xs4">
   		  学院名：
		  <div class="layui-inline">
		    <input class="layui-input" name="infoName" id="academy_name" autocomplete="off">
		  </div>
		  <button class="layui-btn" data-type="reAcademy">搜索</button><button class="layui-btn" data-type="addAcademy">添加</button>
		  
		  
      <table class="layui-hide" id="academy_form" lay-filter="academy"></table> 
   </div>
    <div class="layui-col-xs4">
    		  专业名：
		  <div class="layui-inline">
		    <input class="layui-input" name="infoName" id="major_name" autocomplete="off">
		  </div>
		  <button class="layui-btn" data-type="reMajor">搜索</button><button class="layui-btn" data-type="addMajor">添加</button>
		  
		  <div id="nowAcademy" class="active"></div>
		  
		  
      <table class="layui-hide" id="major_form" lay-filter="major"></table> 
   </div>
      <div class="layui-col-xs4">
      		  班级名：
		  <div class="layui-inline">
		    <input class="layui-input" name="infoName" id="class_name" autocomplete="off">
		  </div>
		  <button class="layui-btn" data-type="reClass">搜索</button><button class="layui-btn" data-type="addClass">添加</button>
		  <div id="nowMajor" class="active"></div>
		  
      <table class="layui-hide" id="class_form" lay-filter="class"></table> 
   </div>
	</div>

 		

</div>              
          

 
<script>
var academyId="";
var majorId="";
var classId="";
layui.use(['table'], function(){
  var table = layui.table;
  
  function findAcademy(){
	  var academyName = $('#academy_name');
      table.reload("academy_form",{
    	  url:'<%=path %>/biz/Info_list'
    	  ,where: {
    		  infoName: academyName.val(),
    		  level: 1
    	  }
          ,page: {
            curr: 1 //重新从第 1 页开始
          }
      });
  }
  
  function findMajor(){
	  var majorName = $('#major_name');
      table.reload("major_form",{
    	  url:'<%=path %>/biz/Info_list'
    	  ,where: {
    		  infoName: majorName.val(),
    		  infoParent: academyId,
    		  level: 2
    	  }
          ,page: {
            curr: 1 //重新从第 1 页开始
          }
      });
  }
  
  function findClass(){
      var className = $('#class_name');
      table.reload("class_form",{
    	  url:'<%=path %>/biz/Info_list'
    	  ,where: {
    		  infoName: className.val(),
    		  infoParent: majorId,
    		  level: 3
    	  }
          ,page: {
            curr: 1 //重新从第 1 页开始
          }
      });
  }
  
  //表格加载
  //学院部分
  table.render({
	    elem: '#academy_form'
	    ,url:'<%=path %>/biz/Info_list'
   	    ,where: {
   		  level: 1
   	    }
	    ,page: true
	    ,cols: [[
	      {field:'infoName',  title: '学院名'}
	      ,{fixed: 'right', title:'操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
 		 ,id: 'academy_form'
	  });
  
  
	  //监听工具条
	  table.on('tool(academy)', function(obj){
	    var data = obj.data;
		if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
	        obj.del();
	        $.post('<%=path %>/biz/Info_del',{"id":data.id},function(){});
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
	    	  layer.open({
	    		  title: '修改学院',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=path %>/biz/Info_toEditAcademy?id='+data.id,
	    		  end : function(layero, index){
	    			  findAcademy();
	    		  }
	    	  });
	    }
	  });
	  
	  table.on('tool(major)', function(obj){
		    var data = obj.data;
			if(obj.event === 'del'){
		      layer.confirm('真的删除行么', function(index){
		        obj.del();
		        $.post('<%=path %>/biz/Info_del',{"id":data.id},function(){});
		        layer.close(index);
		      });
		    } else if(obj.event === 'edit'){
		    	  layer.open({
		    		  title: '修改专业',
		    		  type: 2, 
		    		  area: ['50%', '90%'],
		    		  content: '<%=path %>/biz/Info_toEditMajor?id='+data.id,
		    		  end : function(layero, index){
		    			  findMajor();
		    		  }
		    	  });
		    }
		  });
	  
	  table.on('tool(class)', function(obj){
		    var data = obj.data;
			if(obj.event === 'del'){
		      layer.confirm('真的删除行么', function(index){
		        obj.del();
		        $.post('<%=path %>/biz/Info_del',{"id":data.id},function(){});
		        layer.close(index);
		      });
		    } else if(obj.event === 'edit'){
		    	  layer.open({
		    		  title: '修改专业',
		    		  type: 2, 
		    		  area: ['50%', '90%'],
		    		  content: '<%=path %>/biz/Info_toEditClass?id='+data.id,
		    		  end : function(layero, index){
		    			  findClass();
		    		  }
		    	  });
		    }
		  });
	  
  
  	//专业部分
  	  table.render({
	    elem: '#major_form'
	    ,url:'<%=path %>/biz/Info_list'
   	    ,where: {
   		  level: 2
   	    }
	    ,page: true
	    ,cols: [[
	      {field:'infoName',  title: '专业名'}
	      ,{fixed: 'right', title:'操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
 		 ,id: 'major_form'
	  });
  	//班级部分
	  table.render({
	    elem: '#class_form'
	    ,url:'<%=path %>/biz/Info_list'
   	    ,where: {
   		  level: 3
   	    }
	    ,page: true
	    ,cols: [[
	      {field:'infoName',  title: '班级名'}
	      ,{fixed: 'right', title:'操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
 		 ,id: 'class_form'
	  });
  
	  //监听学院行单击事件
	  table.on('rowDouble(academy)', function(obj){
	    var data = obj.data;
	    //设置当前学院信息
	    $("#nowA").remove();
	    $("#nowAcademy").append("<div id='nowA'>当前学院："+data.infoName+"                <button class='layui-btn' data-type='delNowA'>重置</button></div>");
	    academyId = data.id;
	    //重载专业表格
	      table.reload("major_form",{
	    	  url:'<%=path %>/biz/Info_list'
	    	  ,where: {
	    		  infoParent: academyId,
	    		  level: 2
	    	  }
	          ,page: {
	            curr: 1 //重新从第 1 页开始
	          }
	      });
	  });
	  
	  
	  //监听专业行单击事件
	  table.on('rowDouble(major)', function(obj){
	    var data = obj.data;
	    //设置当前学院信息
	    $("#nowM").remove();
	    $("#nowMajor").append("<div id='nowM'>当前专业："+data.infoName+"                <button class='layui-btn' data-type='delNowM'>重置</button></div>");
	    majorId = data.id;
	    //重载专业表格
	      table.reload("class_form",{
	    	  url:'<%=path %>/biz/Info_list'
	    	  ,where: {
	    		  infoParent: majorId,
	    		  level: 3
	    	  }
	          ,page: {
	            curr: 1 //重新从第 1 页开始
	          }
	      });
	  });
  	
  	
  //事件触发	
  	var $ = layui.$, active = {
		  //模糊搜索学院
	  reAcademy: function(){
		  findAcademy();
	      //执行重载
	    },
 		//模糊搜索专业
	  reMajor: function(){
		  findMajor();
	    },
      //模糊搜索班级
	  reClass: function(){
		  findClass()
	    },
	    
	  //删除当前作为搜索条件的学院条件
	  delNowA: function(){
		  $("#nowA").remove();
		  academyId = "";
		  findMajor();
	      //执行重载
	    },
      
      //删除当前作为搜索条件的专业条件
	  delNowM: function(){
		  $("#nowM").remove();
		  majorId = "";
		  findClass();
	      //执行重载
	    },
	    
	    addAcademy: function(){
	    	  layer.open({
	    		  title: '添加学院',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=basePath%>/biz/Info_toAddAcademy',
	    		  end : function(layero, index){
	    			  findAcademy();
	    		  }
	    	  });
	    },
	    
	    addMajor: function(){
	    	  layer.open({
	    		  title: '添加专业',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=basePath%>/biz/Info_toAddMajor?result='+academyId,
	    		  end : function(layero, index){
	    			  findMajor();
	    		  }
	    	  });
	    },
	    
	    addClass: function(){
	    	  layer.open({
	    		  title: '添加班级',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=basePath%>/biz/Info_toAddClass?result='+majorId,
	    		  end : function(layero, index){
	    			  findClass();
	    		  }
	    	  });
	    }
 
	};
	  
	  $('.layui-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
		//监听动态元素
	    $('.active').on('click','.layui-btn', function () {
		    var type = $(this).data('type');
		    active[type] ? active[type].call(this) : '';
	    });
  
});
</script>



    <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>

</body>
</html>